package dongchel.vrp.immunes;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import dongchel.vrp.entity.MultiObjectiveObject;
import dongchel.vrp.entity.Solution;
import dongchel.vrp.general.CompareObject;
import dongchel.vrp.general.MultiObjectiveComparator;

public class Affinity {
	private List<Double> affinity = new ArrayList<Double>();

	public List<Double> getAffinity() {
		return affinity;
	}

	public void setAffinity(List<Double> affinity) {
		this.affinity = affinity;
	}

	public Affinity(List<Solution> population){
		double distance0 = (Double)(population.get(0).getObjectiveValue().getObjectiveList().get(1));
		double distance = 0;
		for(int i=0;i<population.size();i++) {
			distance = (Double)(population.get(i).getObjectiveValue().getObjectiveList().get(1));
			affinity.add(distance - distance0); 
		}
		double sum = 0;
		for(int i=0;i<population.size();i++) {
			sum += affinity.get(i);
		}
		for(int i=0;i<population.size();i++) {
			affinity.set(i, affinity.get(i)/sum);
		}
	}
	
	public List<Double> accumulateAffinity() {
		List<Double> accumuAff = new ArrayList<Double> ();
		accumuAff.add(this.affinity.get(0));
		for(int i=1;i<this.affinity.size();i++) {
			accumuAff.add(accumuAff.get(i-1)+this.affinity.get(i));
			//System.out.println("accumuAff.get(i):"+accumuAff.get(i));
		}
		return accumuAff;
	}
}
